<%-- 
    Document   : admsupervisor
    Created on : 08/10/2013, 04:26:16 AM
    Author     : grakeskull
--%>
<%@page import="java.util.Date"%>
<%@page import="edu.capex.farmacus.encapsulates.VendedorfarmaciamedicamentoPK"%>
<%@page import="edu.capex.farmacus.encapsulates.Medicamentos"%>
<%@page import="edu.capex.farmacus.Manager.MedicamentosManager"%>
<%@page import="edu.capex.farmacus.Manager.VendedorFarmaciaMedicamentoManager"%>
<%@page import="edu.capex.farmacus.encapsulates.Vendedorfarmaciamedicamento"%>
<%@page import="edu.capex.farmacus.encapsulates.Autenticacion"%>
<%@page import="edu.capex.farmacus.Manager.FarmaciasManager"%>
<%@page import="edu.capex.farmacus.encapsulates.Farmacias"%>
<%@page import="edu.capex.farmacus.Manager.VendedoresManager"%>
<%@page import="edu.capex.farmacus.encapsulates.Vendedores"%>
<!DOCTYPE html>

<%
    if (request.getParameterValues("medicamentos") != null && request.getParameter("vendedor") != null && request.getParameter("farmacia") != null && request.getParameter("observacion") != null) {
        for (String medicamento : request.getParameterValues("medicamentos")) {
            Vendedorfarmaciamedicamento vendedorFarmacia = new Vendedorfarmaciamedicamento();
            vendedorFarmacia.setMedicamentos(new MedicamentosManager().findMedicamentos(new Integer(medicamento)));
            vendedorFarmacia.setVendedores(new VendedoresManager().findVendedores(new Integer(request.getParameter("vendedor"))));
            vendedorFarmacia.setFarmacias(new FarmaciasManager().findFarmacias(new Integer(request.getParameter("farmacia"))));
            vendedorFarmacia.setVendedorfarmaciamedicamentoPK(new VendedorfarmaciamedicamentoPK(new Integer(request.getParameter("vendedor")), new Integer(request.getParameter("farmacia")), new Integer(medicamento), new Date(0)));
            vendedorFarmacia.setCobro(0);
            vendedorFarmacia.setObservacion(request.getParameter("observacion"));
            vendedorFarmacia.setVenta(0);
            new VendedorFarmaciaMedicamentoManager().create(vendedorFarmacia);
        }
    }
%>

<html>
    <head>
        <%@include file="/resources/header.jsp" %>
        <!--<script src="/farmacus/resources/javascript/bsa.js"></script>-->
    </head>

    <body class="preview" data-spy="scroll" data-target=".subnav" data-offset="80">

        <%@include file="/resources/header1.jsp" %>
        <div class="container">


            <h2>Bienvenido <%=((Autenticacion) request.getSession().getAttribute("usuarioLogeado")).getUsuario()%></h2>
            <div class="subnav">
                <ul class="nav nav-pills">
                    <li><a href="<%=request.getContextPath()%>/admin/supervisores/admsupervisor.jsp">Asignar Labor</a></li>
                    <li><a href="Asignadosvendedor.jsp">Ver Asignados</a></li>
                    <li><a href="/farmacus/reportes.jsp">Reportes</a></li>
                    <li><a href="<%=request.getContextPath()%>/admin/mantenimientos/mantenimientos.jsp">Mantenimientos</a></li>
                </ul>
            </div>
            <form class="form-horizontal well" method="POST">
                <fieldset>
                    <h2>Asignar Labor al Vendedor</h2>
                    <center>
                        <div class="control-group">
                            <label class="control-label" for="select01">Tipo Usuario</label>
                            <div class="controls">
                                <select id="selectVendedores">
                                    <option>Vendedor</option>
                                    <option>Visitador</option>

                                </select>
                            </div>
                        </div>

                        <div class="control-group">

                            <label class="control-label" for="input01">Vendedor</label>
                            <div class="controls">
                                <select name="vendedor">
                                    <%
                                        for (Vendedores temp : new VendedoresManager().findVendedoresEntities()) {
                                    %>
                                    <option value="<%=temp.getId()%>"><%=temp.getNombre()%></option>
                                    <%}%>
                                </select>
                            </div>
                        </div>
                        <div class="control-group">

                            <label class="control-label" for="input02">Medicamentos</label>
                            <div class="controls">
                                <select name="medicamentos" multiple="">
                                    <%
                                        for (Medicamentos temp : new MedicamentosManager().findMedicamentosEntities()) {
                                    %>
                                    <option value="<%=temp.getIdmedicamentos()%>"><%=temp.getNombreMedicamento()%></option>
                                    <%}%>
                                </select>
                            </div>
                        </div>
                        <div class="control-group">

                            <label class="control-label" for="input02">Farmacia</label>
                            <div class="controls">
                                <select name="farmacia">
                                    <%
                                        for (Farmacias temp : new FarmaciasManager().findFarmaciasEntities()) {
                                    %>
                                    <option value="<%=temp.getId()%>"><%=temp.getNombre()%></option>
                                    <%}%>
                                </select>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="textarea">Observacion</label>
                            <div class="controls">
                                <textarea class="input-xlarge" id="textarea" rows="3" name="observacion"></textarea>
                            </div>
                        </div>

                        <div class="form-actions">
                            <button type="submit" class="btn btn-primary">Guardar</button>
                            <button type="reset" class="btn">Cancel</button>
                        </div>
                    </center>
                </fieldset>

            </form>
            <table id="myTable" class="table table-bordered table-striped">
                <thead>
                    <tr>
                        <th filter-type="ddl">
                            Vendedor
                        </th>
                        <th filter-type="ddl">
                            Medicamento
                        </th>
                        <th filter-type="ddl">
                            Farmacias
                        </th>
                        <th>
                            Venta
                        </th>
                        <th>
                            Costo
                        </th>
                        <th>
                            Observacion
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <%
                        for (Vendedorfarmaciamedicamento temp : new VendedorFarmaciaMedicamentoManager().findVendedorfarmaciamedicamentoEntities()) {
                    %>
                    <tr>
                        <td>
                            <%=temp.getVendedores().getNombre()%>
                        </td>
                        <td>
                            <%=temp.getMedicamentos().getNombreMedicamento()%>
                        </td>
                        <td>
                            <%=temp.getFarmacias().getNombre()%>
                        </td>
                        <td>
                            <%=temp.getVenta()%>
                        </td>
                        <td>
                            <%=temp.getCobro()%>
                        </td>
                        <td>
                            <%=temp.getObservacion()%>
                        </td>
                    </tr>
                    <%}%>
                </tbody>
            </table>
            <%@include file="/resources/footer1.jsp" %>
        </div>
        <script type="text/javascript">
            $(document).ready(function() {
                $("#myTable").tableFilter();
                $("#selectVendedores").change(function() {
                    window.location.replace("/farmacus/admin/supervisores/admsupervisorVendedor.jsp");
                });
            });
        </script>
    </body>
</html>
